import hashlib
import hmac
import uuid

from configs import config


def generate_uuid():
    new_id = hashlib.sha256(config.SESSION_SECRET + uuid.uuid4().bytes)
    return new_id.hexdigest()


def generate_token(uuid, mobile, sms_code):
    return hmac.new(config.SESSION_SECRET, (f"{uuid} {mobile} {sms_code}").encode(), hashlib.sha256).hexdigest()


unique_id = generate_uuid()
print(unique_id)
print(generate_token(unique_id, 111, 2222))

# import os
#
# dir = os.path.dirname(os.path.abspath(__file__))
# filename = os.path.join(dir, 'sdfdf.txt')
# print(filename)
#
# with open(filename, 'wb') as f:
#     f.write(b'hello world')
